package com.lonely.deliver.domain.dto;

import com.lonely.common.enums.WebSocketBusinessStatusEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * 同步数据进度条
 *
 * @author fzzf
 */
@Data
public class SyncProgressDTO implements Serializable {

    /**
     * 进度
     */
    private int progress;

    /**
     * 消息
     */
    private String message;

    /**
     * 状态
     *
     * @see WebSocketBusinessStatusEnum
     */
    private String status;

    /**
     * 时间戳
     */
    private long timestamp;


    public SyncProgressDTO() {
    }

    public SyncProgressDTO(int progress, String message, String status) {
        this.progress = progress;
        this.message = message;
        this.status = status;
        this.timestamp = System.currentTimeMillis();
    }

    /**
     * 构建错误进度实体
     *
     * @param message
     * @return
     */
    public static SyncProgressDTO buildErrorResult(String message) {
        SyncProgressDTO syncProgressDTO = new SyncProgressDTO();
        syncProgressDTO.setMessage(message);
        syncProgressDTO.setStatus(WebSocketBusinessStatusEnum.ERROR.name());
        syncProgressDTO.setTimestamp(System.currentTimeMillis());
        return syncProgressDTO;
    }

    /**
     * 构建已完成的进度实体
     *
     * @param message
     * @return
     */
    public static SyncProgressDTO buildCompletedResult(String message) {
        SyncProgressDTO syncProgressDTO = new SyncProgressDTO();
        syncProgressDTO.setProgress(100);
        syncProgressDTO.setMessage(message);
        syncProgressDTO.setStatus(WebSocketBusinessStatusEnum.COMPLETED.name());
        syncProgressDTO.setTimestamp(System.currentTimeMillis());
        return syncProgressDTO;
    }


    /**
     * 构建进行中的进度实体
     *
     * @param progress
     * @param message
     * @return
     */
    public static SyncProgressDTO buildProgressResult(int progress, String message) {
        SyncProgressDTO syncProgressDTO = new SyncProgressDTO();
        syncProgressDTO.setProgress(progress);
        syncProgressDTO.setMessage(message);
        syncProgressDTO.setStatus(WebSocketBusinessStatusEnum.IN_PROGRESS.name());
        syncProgressDTO.setTimestamp(System.currentTimeMillis());
        return syncProgressDTO;
    }
}